<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>权限列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/icon.css}">
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.easyui.min.js}"></script>
    <script type="text/javascript">
        //工具栏
        var toolbar = [{
            text: '修改',
            iconCls: 'icon-edit',
            handler: function () {
                let selected = $('#permissionlist').datagrid('getSelected');
                if (!selected) {
                    alert("请选择要修改的条目");
                } else {
                    let combobox = $("#parentid");
                    if (selected.parentPermission == null){
                        combobox.combobox({disabled:true});
                        combobox.combobox('setValue',"根权限");
                    }else {
                        combobox.combobox({disabled:false});
                        combobox.combobox('setValue',selected.parentPermission.id);
                    }
                    $("#id").textbox('setValue',selected.id);
                    $("#url").textbox('setValue',selected.url);
                    $("#name").textbox('setValue',selected.name);
                    $("#sname").textbox('setValue',selected.sname);

                    $('#dd').dialog('open');
                }
            }
        }];
        $(function () {
            $("#parentnameKey").val("");
            $("#premissionKey").val("");
            $('#permissionlist').datagrid({
                title: '权限列表',
                iconCls: 'icon-save',
                url:"/manager/permission/findAll",
                columns: [
                    [
                        {field: 'id', title: '权限ID', width: 100, align: 'center'},
                        {field: 'name', title: '权限名称', width: 200, align: 'center'},
                        {field: 'url', title: '权限URL', width: 100, align: 'center'},
                        {field: 'parentPermission', title: '权限所在模块', width: 150, align: 'center',formatter:function (value,row, index) {
                                if (value == null){
                                    return "根权限";
                                }
                                 return value.name;
                            }},
                        {field: 'sname', title: '权限操作名称', width: 350, align: 'center'}
                    ]
                    ],
                pagination: true,
                toolbar: toolbar,
                pageSize: 5,
                singleSelect: true,
                pageList: [5, 10, 20]
            });
            //初始化查询栏
            $("#submit_search").linkbutton({iconCls: 'icon-search', plain: true})
                .click(function () {
                    $('#permissionlist').datagrid({
                        queryParams: {
                            "parentnameKey": $("#parentnameKey").val(),
                            "premissionKey": $("#premissionKey").val()
                        }
                    });   //点击搜索
                });

            //初始化修改窗口
            $('#dd').dialog({
                title: '修改权限',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                href: '',
                modal: true,
                iconCls: 'icon-save',
                buttons: [{
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: function () {
                        $("#permission").form({
                            url: "permission/modifyPermission",
                            success: function (data) {
                                $('#dd').dialog('close');
                                alert(JSON.parse(data).msg);
                                $('#permissionlist').datagrid('reload');
                            }
                        })
                        $("#permission").submit();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#dd').dialog('close');
                    }
                }]
            });

            //初始化下拉控件
            $("#parentid").combobox({
                url: "/manager/permission/findRootPermissions",
                prompt:'请选择权限模块',
                value:"",
                valueField: "id",
                textField: "name"
            });

        });
    </script>
</head>
<body>
<form name="searchform" method="post" action="" id="searchform">
    <td width="70" height="30"><strong>权限查询：</strong></td>
    <td height="30">
        <input type="text" id="parentnameKey" size=20 placeholder="模块名称"/>
        <input type="text" id="premissionKey" size=20 placeholder="权限名称"/>
        <a id="submit_search">搜索</a>
    </td>
</form>
<table id="permissionlist"></table>
<div id="dd">
    <div align="center" style="margin-top: 30px">
        <form id="permission" method="post">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="id" id="id" style="width:50%" data-options="label:'权限ID:'"
                       readonly="readonly"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  id="url" style="width:50%" data-options="label:'权限url:'"
                       readonly="readonly"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="name" id="name" style="width:50%"
                       data-options="label:'权限名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="sname" id="sname" style="width:50%"
                       data-options="label:'操作名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" name="parentid" id="parentid" label="所属模块:" style="width:50%">
                </select>
            </div>
        </form>
    </div>
</div>
</body>
</html>